package com.lipei.vrp.imp;

import java.util.ArrayList;

import org.apache.commons.lang3.StringUtils;

import com.lipei.vrp.AlgorithmType;
import com.lipei.vrp.Context;
import com.lipei.vrp.IAlgorithm;
import com.lipei.vrp.IAlgorithmCreator;

public class VRP_init implements IAlgorithmCreator {

	private class Impl extends AbstractAlgorithm implements IAlgorithm {

		public Impl(String[] args) {
			super(args);
			if (args.length != 3) {
				throw new RuntimeException(
						"argument should be vrp_sa name number");
			}

			if (StringUtils.equals(args[2], "0")) {
				m = 0;
				algtype = AlgorithmType.INITM0;
			} else if (StringUtils.equals(args[2], "1")) {
				m = 1;
				algtype = AlgorithmType.INITM1;
			} else {
				throw new RuntimeException("m value must be 0 or 1");
			}
			this.args = args;
		}

		@Override
		public ArrayList<String> generateCommand(String vrppath) {
			ArrayList<String> commands = new ArrayList<String>();
			commands.add(Context.initpath);
			commands.add("-f");
			commands.add(vrppath);
			commands.add("-m");
			commands.add(args[2]);

			String command = Context.initpath + " -f \"" + vrppath + "\" -m "
					+ args[2];
			return commands;
		}
	}

	@Override
	public IAlgorithm argsCheck(String[] args) {
		return new Impl(args);
	}

	public static IAlgorithmCreator createIns() {
		// TODO Auto-generated method stub
		return new VRP_init();
	}

}
